﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CNVP.Framework;
using System.Data;
using CNVP.JShop.UI;
using CNVP.Framework.Utils;
using CNVP.Framework.Helper;

namespace CNVP.JShop.Web.Admin
{
    public partial class LinksClassList : AdminPage
    {
        BLL.CNVP_Column bll = new BLL.CNVP_Column();
        public int rplistCount = 0;
        public int PageIndex = 1;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!BLL.BLLCheckAdmin.LoginOk(Page, 113)) return;//判断页面权限
            if (!string.IsNullOrEmpty(Request.QueryString["Page"]) && Public.IsNumber(Request.QueryString["Page"]))
            {
                PageIndex = Convert.ToInt32(Request.QueryString["Page"]);
            }
            if (!IsPostBack)
            {
                StartLoad(PageIndex);
            }
            btDelete.Attributes.Add("onclick", "if(ifCheck()){return confirm('确定删除该记录吗?');}else{alert('请选择记录！');return false;};");
        }

        /// <summary>
        /// PageNavigator1_PageChange 的摘要说明
        /// 分页加载列表函数
        /// </summary>
        protected void StartLoad(int PageIndex)
        {
            SQLConditionInfo[] st = new SQLConditionInfo[2];
            st[0] = new SQLConditionInfo("@ColumnType", "1");
            st[1] = new SQLConditionInfo("@ColumnName", Public.FilterSql(txtkey.Text.Trim()));
            int i, j;
            DataTable dt = null;
            int pageNum = 20;
            dt = bll.GetPage(this.GetType().Name, PageIndex, pageNum, out i, out j, st);
            
            rpList.DataSource = dt;
            rpList.DataBind();
            paging.InnerHtml = Paginator.Pagination(PageIndex, i, j);
        }

        protected void btDelete_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < this.rpList.Items.Count; i++)
            {
                CheckBox cbCheck = (CheckBox)this.rpList.Items[i].FindControl("cbCheck");
                if (cbCheck.Checked == true)
                {
                    int code = int.Parse(cbCheck.ToolTip);
                    var Links_List = new BLL.CNVP_Links().GetAll_CNVP_Links("LinkClassID=" + code + "");
                    if (Links_List.Count > 0)
                    {
                        BasePage.MessageBoxGoHistory("该类别存在友情链接中,不允许删除.！");
                        return;
                    }
                    else
                    {
                        int rows = bll.Delete_CNVP_Column(code);
                        if (rows == 1)
                        {
                            StartLoad(PageIndex);
                        }
                        else { BasePage.MessageBoxGoHistory("删除失败！"); }
                    }
                }
            }
            StartLoad(PageIndex);
        }


        protected void btAdd_Click(object sender, EventArgs e)
        {
            Response.Redirect("LinksClassEdit.aspx");
        }

        protected void btSearch_Click(object sender, ImageClickEventArgs e)
        {
            StartLoad(PageIndex);
        }
    }
}